package com.edu.controller;

import com.alibaba.druid.util.StringUtils;
import com.edu.dto.SchoolCountStuDto;
import com.edu.entity.StuUpInfo;
import com.edu.service.StuUpInfoService;
import com.edu.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: graduate
 * @description: 预报名
 * @author: K.faWu
 * @create: 2021-05-23 14:03
 **/

@RestController
@RequestMapping("stuUp")
@Slf4j
public class StuUpInfoController {

    @Autowired
    private StuUpInfoService stuUpInfoService;

    /**
     * 学生预报名
     */
    @PostMapping("/addStuInfo")
    public Result add(@RequestBody StuUpInfo stuUpInfo){

        String result = stuUpInfoService.add(stuUpInfo);
        if(StringUtils.isEmpty(result))
            return Result.success();
        return Result.failure("", result);
    }

    /**
     * 正式报名后生成考生号
     */
    @GetMapping("/{SchoolId}")
    public Result upCandidate(@PathVariable Integer SchoolId){
        Long count = stuUpInfoService.upCandidate(SchoolId);
        return Result.success("考生号已分配完毕",count);
    }

    /**
     * 查询每个学校的预报名人数
     */
    @PostMapping("/countByschoolList")
    public Result countByShoolList(String ids){
        List<Long> schoolList = new ArrayList<>();
        if(!StringUtils.isEmpty(ids)) {
            String[] arr = ids.split(",");
            for (String s : arr) {
                schoolList.add(Long.parseLong(s));
            }
        }
        return stuUpInfoService.countByShoolList(schoolList);
    }

    /**
     * 学生报名
     */
    @PostMapping("/addStuInfoStandard")
    public Result addStuInfoStandard(@RequestBody StuUpInfo stuUpInfo){
        return stuUpInfoService.addStuInfoStandard(stuUpInfo);
    }
}
